home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / os2 / sidis100.zip / USERCTRL / MAILPROC.CMD < prev    next >
OS/2 REXX Batch file  |  1996-05-25  |  11KB  |  360 lines

  1. /************************************************************************/
  2. /*                                                                      */
  3. /*  REXX Mail processor                                                 */
  4. /*                                                                      */
  5. /* (C) 1996, Axel Mueller (amueller@stargate.rz.fh-offenburg.de)        */
  6. /*     Version 1.0     05/16/96                                         */
  7. /************************************************************************/
  8.  
  9. parse arg MailInFile
  10.  
  11. call on error
  12.  
  13.  
  14. /************************************************************************/
  15. /*                                                                      */
  16. /* Setup                                                                */
  17. /*                                                                      */
  18. /************************************************************************/
  19.  
  20.  
  21. True            = 1
  22. False        = 0
  23.  
  24.  
  25. /**************/
  26. /*   setup    */
  27. /**************/
  28.  
  29. ETCPath                = value('ETC',,'OS2ENVIRONMENT')
  30. MailOutFile            = left(MailInFile, (length(MailInFile)-4))'.rsp'
  31. LogFile                = ETCPath'\mailproc.log'
  32. ContactAddress        = 'amueller@stargate.rz.fh-offenburg.de'
  33. Hostname                = value('HOSTNAME',,'OS2ENVIRONMENT')
  34.  
  35. ResolvFile            = ETCPath'\resolv'
  36. Line = linein(ResolvFile)
  37. do while (left(Line,6) <> 'domain')
  38.     Line = linein(ResolvFile)
  39. end
  40. rc = lineout(ResolvFile)
  41. parse value Line with dummy Domain
  42.  
  43. HostDomain            = Hostname'.'Domain
  44.  
  45.  
  46.  
  47. /*#################################################*/
  48. /*#              main routine                     #*/
  49. /*#################################################*/
  50.  
  51. Line = linein(MailInFile)
  52. do while (left(Line,8) <> 'Subject:')
  53.     Line = linein(MailInFile)
  54. end
  55. rc = lineout(MailInFile)
  56.  
  57. parse value Line with Subject User Password CommandArguments
  58. parse value CommandArguments with Command Argument1 Argument2
  59.  
  60. if User=="HELP" | User=="help" then
  61.     Command = "HELP"
  62. parse upper value Command with Command
  63.  
  64.  
  65. Line = linein(MailInFile)
  66. do while (left(Line,5) <> 'From:')
  67.     Line = linein(MailInFile)
  68. end
  69. rc = lineout(MailInFile)
  70.  
  71. parse value Line with From ResponseAddress ResponseName
  72.  
  73. call log('Received mail 'Line)
  74.  
  75.  
  76. select
  77.     when ((Command='CHANGE_PASSWORD') | (Command='C_P')) & (Argument2=="") then
  78.         call change_password
  79.     when ((Command='FORWARD_MAIL') | (Command='F_M')) & (Argument2=="") then
  80.         call forward_mail('0')
  81.     when ((Command='FORWARD_COPY') | (Command='F_C')) & (Argument2=="") then
  82.         call forward_mail('1')
  83.     when ((Command='STOP_FORWARD') | (Command='S_F')) & (Argument1=="") & (Argument2=="") then
  84.         call stop_forward
  85.     when Command='HELP' then
  86.         call help
  87.     otherwise
  88.         call unknown_command
  89. end
  90.  
  91. call log('Finished mail processing')
  92.  
  93.  
  94. exit
  95.  
  96.  
  97. /*#################################################*/
  98. /*#          mail processor commands              #*/
  99. /*#################################################*/
  100.  
  101.  
  102. /*****************************/
  103. /* change_password           */
  104. /*****************************/
  105.  
  106. change_password:
  107.  
  108.     call log('... password change request')
  109.     if (RxPrfCheckPassword(User, Password)) then
  110.         do
  111.          rc = RxPrfSetPassword(User, Argument1)
  112.          call write_robot_header
  113.          rc = lineout(MailOutFile, '*** Password has been successfully changed.')
  114.          rc = lineout(MailOutFile, '*** Do not forget your new password in order to be able to')
  115.          rc = lineout(MailOutFile, '*** login via modem and retrieve mails.')
  116.          call write_contact
  117.          rc = lineout(MailOutFile)
  118.          call log('... password has been changed')
  119.         end
  120.     else
  121.         do
  122.          call refuse_action
  123.          call write_contact
  124.          rc = lineout(MailOutFile)
  125.         end
  126.  
  127.     return
  128.  
  129.  
  130.  
  131. /*****************************/
  132. /* forward_mail              */
  133. /*****************************/
  134.  
  135. forward_mail:
  136.  
  137.     parse arg ForwardCopy
  138.  
  139.     call log('... mail forward request')
  140.     if (RxPrfCheckPassword(User, Password)) then
  141.         do
  142.          call write_robot_header
  143.          OwnAddress = User'@'HostDomain
  144.          if(Argument1 <> OwnAddress) then
  145.              do
  146.               rc = RxPrfSetForwardAddress(User, Argument1, ForwardCopy)
  147.               rc = lineout(MailOutFile, '*** Mail forwarding has been activated.')
  148.               if (ForwardCopy == 1) then
  149.                 do
  150.                   rc = lineout(MailOutFile, '*** A copy of every incoming mail will be forwarded to 'Argument1 )
  151.                   rc = lineout(MailOutFile, '*** The original mails will be keep for POP3 retrieval on this system.' )
  152.                   call log('... copy forward has been activated')
  153.                 end
  154.               else
  155.                 do
  156.                   rc = lineout(MailOutFile, '*** Every incoming mail will be forwarded to 'Argument1 )
  157.                   rc = lineout(MailOutFile, '*** No incoming mail be kept on this system.' )
  158.                   call log('... mail forward has been activated')
  159.                 end
  160.               call write_contact
  161.               rc = lineout(MailOutFile)
  162.              end
  163.          else
  164.              do
  165.               rc = lineout(MailOutFile, '*** Mail forwarding has NOT been activated.')
  166.               rc = lineout(MailOutFile, '*** The forward address specified would create a loop.')
  167.               call write_contact
  168.               rc = lineout(MailOutFile)
  169.               call log('... forward has not been activated in order to avoid loop')
  170.              end
  171.         end
  172.     else
  173.         do
  174.          call refuse_action
  175.          call write_contact
  176.          rc = lineout(MailOutFile)
  177.         end
  178.  
  179.     return
  180.  
  181.  
  182.  
  183. /*****************************/
  184. /* stop_forward              */
  185. /*****************************/
  186.  
  187. stop_forward:
  188.  
  189.     call log('... stop forward request')
  190.     if (RxPrfCheckPassword(User, Password)) then
  191.         do
  192.          rc = RxPrfSetForwardAddress(User, "", '0')
  193.          call write_robot_header
  194.          rc = lineout(MailOutFile, '*** Mail forwarding has been deactivated.')
  195.          call write_contact
  196.          rc = lineout(MailOutFile)
  197.          call log('... mail forward has been deactivated')
  198.         end
  199.     else
  200.         do
  201.          call refuse_action
  202.          call write_contact
  203.          rc = lineout(MailOutFile)
  204.         end
  205.  
  206.     return
  207.  
  208.  
  209.  
  210. /*****************************/
  211. /* help                      */
  212. /*****************************/
  213.  
  214. help:
  215.  
  216.     call write_robot_header
  217.     call write_help
  218.     call write_contact
  219.     rc = lineout(MailOutFile)
  220.     call log('... help requested has been answered')
  221.  
  222.     return
  223.  
  224.  
  225.  
  226. /*****************************/
  227. /* unknown_command           */
  228. /*****************************/
  229.  
  230. unknown_command:
  231.  
  232.     call write_robot_header
  233.     rc = lineout(MailOutFile, '*** Command/Parameter error: 'CommandArguments)
  234.     rc = lineout(MailOutFile, '')
  235.     call write_help
  236.     call write_contact
  237.     rc = lineout(MailOutFile, '   ----- Original message follows -----')
  238.     rc = lineout(MailOutFile, '')
  239.     call write_original_mail
  240.     rc = lineout(MailOutFile)
  241.     call log('... command/parameter error: 'CommandArguments)
  242.  
  243.     return
  244.  
  245.  
  246.  
  247. /*#################################################*/
  248. /*#              sub procedures                   #*/
  249. /*#################################################*/
  250.  
  251.  
  252. /*****************************/
  253. /* write_robot_header        */
  254. /*****************************/
  255.  
  256. write_robot_header:
  257.  
  258.     rc = lineout(MailOutFile, 'This mail was created by an automatic mail processor.')
  259.     rc = lineout(MailOutFile, 'PLEASE DO NOT REPLY TO THIS MAIL.')
  260.     rc = lineout(MailOutFile, '')
  261.  
  262.     return
  263.  
  264.  
  265. /*****************************/
  266. /* write_contact             */
  267. /*****************************/
  268.  
  269. write_contact:
  270.  
  271.     rc = lineout(MailOutFile, '')
  272.     rc = lineout(MailOutFile, 'If you have any questions, suggestions or problems - please contact:')
  273.     rc = lineout(MailOutFile, ContactAddress)
  274.     rc = lineout(MailOutFile, '')
  275.  
  276.     return
  277.  
  278.  
  279.  
  280. /*****************************/
  281. /* write_help                */
  282. /*****************************/
  283.  
  284. write_help:
  285.  
  286.     rc = lineout(MailOutFile, '***********************************************************************')
  287.     rc = lineout(MailOutFile, '*               = SYNTAX FOR MAIL PROCESSOR v0.98 =                   *')
  288.     rc = lineout(MailOutFile, '* (C) Axel Mueller, 1996 (amueller@stargate.rz.fh-offenburg.de)       *')
  289.     rc = lineout(MailOutFile, '*                                                                     *')
  290.     rc = lineout(MailOutFile, '* All commands must be given in the SUBJECT!                          *')
  291.     rc = lineout(MailOutFile, '* Commands and parameter(s) must be separated by SPACE!               *')
  292.     rc = lineout(MailOutFile, '* All commands start with <user> <password> and are followd by        *')
  293.     rc = lineout(MailOutFile, '* <command>     and    <parameter(s)>                                 *')
  294.     rc = lineout(MailOutFile, '*                                                                     *')
  295.     rc = lineout(MailOutFile, '* change_password      <new password>                                 *')
  296.     rc = lineout(MailOutFile, '* forward_mail         <forward address>                              *')
  297.     rc = lineout(MailOutFile, '* forward_copy         <forward address>                              *')
  298.     rc = lineout(MailOutFile, '* stop_forward                                                        *')
  299.     rc = lineout(MailOutFile, '*                                                                     *')
  300.     rc = lineout(MailOutFile, '* Instead of the commands above you can use the following short cuts: *')
  301.     rc = lineout(MailOutFile, '* <command>            <short cut>                                    *')
  302.     rc = lineout(MailOutFile, '*                                                                     *')
  303.     rc = lineout(MailOutFile, '* change_password      c_p                                            *')
  304.     rc = lineout(MailOutFile, '* forward_mail         f_m                                            *')
  305.     rc = lineout(MailOutFile, '* forward_copy         f_c                                            *')
  306.     rc = lineout(MailOutFile, '* stop_forward         s_f                                            *')
  307.     rc = lineout(MailOutFile, '*                                                                     *')
  308.     rc = lineout(MailOutFile, '* You will receive a confirmation mail immediately after your         *')
  309.     rc = lineout(MailOutFile, '* mail has been received by the mail processor.                       *')
  310.     rc = lineout(MailOutFile, '*                                                                     *')
  311.     rc = lineout(MailOutFile, '***********************************************************************')
  312.     
  313.     return
  314.  
  315.  
  316.  
  317. /*****************************/
  318. /* write_original_mail       */
  319. /*****************************/
  320.  
  321. write_original_mail:
  322.  
  323.     MailInFilePos = 0
  324.     MailInFileSize = stream(MailInFile, 'c', 'query size')
  325.     do while (MailInFilePos<MailInFileSize)
  326.         rc = lineout(MailOutFile, Line)
  327.         Line = linein(MailInFile)
  328.         MailInFilePos=MailInFilePos+length(Line)+1
  329.     end
  330.     rc = lineout(MailInFile)
  331.  
  332.     return
  333.  
  334.  
  335. /*****************************/
  336. /* refuse_action             */
  337. /*****************************/
  338.  
  339. refuse_action:
  340.  
  341.     call write_robot_header
  342.     rc = lineout(MailOutFile, '*** You are not authorized for the requested action!')
  343.     call log('... no authorization for requested action')
  344.  
  345.     return
  346.  
  347.  
  348.  
  349. /*****************************/
  350. /* log                       */
  351. /*****************************/
  352.  
  353. log:
  354.  
  355.     parse arg LogString
  356.  
  357.     rc = lineout( LogFile, date(european)' 'time(normal)'' LogString )
  358.  
  359.     return
  360.